# -*- coding: utf-8 -*-

from __future__ import unicode_literals

from django.contrib.auth.models import User
from django.db import models

import shortuuid


def generate_grant_code():
    return shortuuid.ShortUUID().random(length=8)


class State(models.Model):
    user = models.ForeignKey(User, blank=True, null=True)
    hash = models.CharField(max_length=16)
    code = models.CharField(max_length=16, default=generate_grant_code)
    href = models.URLField()
    action = models.CharField(max_length=16)
    is_valid = models.BooleanField(default=False)
    created_time = models.DateTimeField(auto_now_add=True)
